package main

import (
	"container/list"
	"crypto/md5"
	"crypto/sha1"
	"fmt"
	"hash/crc32"
	"sort"
)

type Person struct {
	name string
	age  int
}

type ByName []Person

func (this ByName) Len() int {
	return len(this)
}

func (this ByName) Less(i, j int) bool {
	return this[i].name < this[j].name
}

func (this ByName) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

func main() {
	kids := []Person{{name: "tom", age: 20}, {name: "marks", age: 28}}
	sort.Sort(ByName(kids))
	fmt.Println(kids)

	//
	crc()
	sha()
	md5Str()
}

func linkedList() {
	var x list.List
	x.PushBack(1)
	x.PushBack(2)
	x.PushBack(3)
	for e := x.Front(); e != nil; e = e.Next() {
		fmt.Println(e.Value.(int))
	}
}

//hash算法
func crc() {
	h := crc32.NewIEEE()
	h.Write([]byte("hello"))
	v := h.Sum32()
	fmt.Println(v)

}

func sha() {
	h := sha1.New()
	h.Write([]byte("test"))
	bs := h.Sum([]byte{})
	fmt.Println(bs)
}

//md5加密
func md5Str() {
	h := md5.New()
	h.Write([]byte("hello"))
	bs := h.Sum([]byte{})
	fmt.Print(string(bs))
}
